/**
 * Created by lighter on 2014/12/20.
 */
package Hxw3DEngine.asset.parsers.bson.vo {
public class MaterialBase {

    public var name:String;
    public var cls:uint;
    public var color:uint;
    public var alpha:Number;

    public function MaterialBase(obj:Object) {
        name = obj.name;
        cls = obj["class"];
        color = obj.hasOwnProperty("color")?obj.color:0xffffff;
        alpha = obj.hasOwnProperty("alpha")?obj.alpha:1;
    }

    public static function create(obj:Object):Object{
        return (obj["class"] == 1)?new MaterialTexture(obj):new MaterialColor(obj);
    }

    public function clone():MaterialBase{
        return create(getObject({'class':cls})) as MaterialBase;
    }

    protected function getObject(obj:Object):Object{
        obj.color = this.color;
        obj.alpha = this.alpha;
        return obj;
    }
}
}
